* Using data in year 2018 - 2019 (actual last 2-year data, reported in 2019 and 2020 respectively)
use data_2018_2019, clear

* Summary Stats in 2018-2019
eststo clear
estpost tabstat cei stakeholder_mgmt socialissue_part discrimination benefits happiness at age roa col_emp labormkt ad2at b2c pps eindex iio hqdparty dparty kld_w kld_sm kld_sip if gray==0&cyear>=2011, listwise stat(mean sd p50 min max) columns(stat)
esttab using myfile.rtf, cells("mean(fmt(a3)) sd p50 min max") replace

* Correlation map in 2018-2019
use data_2018_2019, clear
eststo clear
estpost corr at age roa col_emp labormkt ad2at b2c pps eindex iio hqdparty dparty if gray==0&cyear>=2011, matrix listwise
esttab using myfile.rtf, nostar unstack not noobs compress rtf replace

* Determinants of CEI in 2018-2019
use data_2018_2019, clear
eststo clear
eststo r1: xi:reg cei lat lage roa col_emp labormkt ad2at b2c pps eindex iio hqdparty dparty i.cyear if gray==0&cyear>=2011, cluster(fid)
eststo r2: xi:reg cei lat lage roa col_emp labormkt ad2at b2c pps eindex iio hqdparty dparty i.cyear i.sid i.iid if gray==0&cyear>=2011, cluster(fid)
eststo r3: xi:reg cei lat lage roa ad2at b2c pps eindex iio hqdparty dparty i.ysid i.yiid if gray==0&cyear>=2011, cluster(fid)
eststo r4: xtreg cei lat lage roa col_emp labormkt ad2at b2c pps eindex iio hqdparty dparty i.cyear if gray==0&cyear>=2011, fe vce(cluster fid)
esttab using myfile.rtf, star(* 0.10 ** 0.05 *** 0.01) r2 ar2 onecell nolines nogaps compress nomtitles nodepvars constant rtf replace

* Determinants of stakeholder management in 2018-2019
use data_2018_2019, clear
eststo clear
eststo r1: xi:reg stakeholder_mgmt lat lage roa col_emp labormkt ad2at b2c pps eindex iio hqdparty dparty i.cyear if gray==0&cyear>=2011, cluster(fid)
eststo r2: xi:reg stakeholder_mgmt lat lage roa col_emp labormkt ad2at b2c pps eindex iio hqdparty dparty i.cyear i.sid i.iid if gray==0&cyear>=2011, cluster(fid)
eststo r3: xi:reg stakeholder_mgmt lat lage roa ad2at b2c pps eindex iio hqdparty dparty i.ysid i.yiid if gray==0&cyear>=2011, cluster(fid)
eststo r4: xtreg stakeholder_mgmt lat lage roa col_emp labormkt ad2at b2c pps eindex iio hqdparty dparty i.cyear if gray==0&cyear>=2011, fe vce(cluster fid)
esttab using myfile.rtf, star(* 0.10 ** 0.05 *** 0.01) r2 ar2 onecell nolines nogaps compress nomtitles nodepvars constant rtf replace

* Determinants of social issue participation in 2018-2019
use data_2018_2019, clear
eststo clear
eststo r1: xi:reg socialissue_part lat lage roa col_emp labormkt ad2at b2c pps eindex iio hqdparty dparty i.cyear if gray==0&cyear>=2011, cluster(fid)
eststo r2: xi:reg socialissue_part lat lage roa col_emp labormkt ad2at b2c pps eindex iio hqdparty dparty i.cyear i.sid i.iid if gray==0&cyear>=2011, cluster(fid)
eststo r3: xi:reg socialissue_part lat lage roa ad2at b2c pps eindex iio hqdparty dparty i.ysid i.yiid if gray==0&cyear>=2011, cluster(fid)
eststo r4: xtreg socialissue_part lat lage roa col_emp labormkt ad2at b2c pps eindex iio hqdparty dparty i.cyear if gray==0&cyear>=2011, fe vce(cluster fid)
esttab using myfile.rtf, star(* 0.10 ** 0.05 *** 0.01) r2 ar2 onecell nolines nogaps compress nomtitles nodepvars constant rtf replace

* LGBTQ-related and Placebo Shareholder Proposals (this will not work properly without sufficient data before 2018)
use data_2018_2019, clear
keep if year >= 2011 & gray == 0
egen min_pro_year = min(cyear) if proposal == 1, by(fid)
egen min_pro_year2 = min(min_pro_year), by(fid)
gen post_pro = 1 if year > min_pro_year2
replace post_pro = 0 if post_pro == .

egen min_law_year = min(cyear) if law == 1, by(fid)
egen min_law_year2 = min(min_law_year), by(fid)
gen post_law = 1 if year > min_law_year2
replace post_law = 0 if post_law == .

eststo clear
eststo r1: xtreg cei post_pro lat lage roa col_emp labormkt ad2at b2c pps eindex iio hqdparty dparty i.cyear if gray==0&cyear>=2011, fe vce(cluster fid)
eststo r2: xtreg stakeholder_mgmt post_pro lat lage roa col_emp labormkt ad2at b2c pps eindex iio hqdparty dparty i.cyear if gray==0&cyear>=2011, fe vce(cluster fid)
eststo r3: xtreg socialissue_part post_pro lat lage roa col_emp labormkt ad2at b2c pps eindex iio hqdparty dparty i.cyear if gray==0&cyear>=2011, fe vce(cluster fid)
eststo r4: xtreg cei post_law lat lage roa col_emp labormkt ad2at b2c pps eindex iio hqdparty dparty i.cyear if gray==0&cyear>=2011, fe vce(cluster fid)
eststo r5: xtreg stakeholder_mgmt post_law lat lage roa col_emp labormkt ad2at b2c pps eindex iio hqdparty dparty i.cyear if gray==0&cyear>=2011, fe vce(cluster fid)
eststo r6: xtreg socialissue_part post_law lat lage roa col_emp labormkt ad2at b2c pps eindex iio hqdparty dparty i.cyear if gray==0&cyear>=2011, fe vce(cluster fid)
esttab using myfile.rtf, star(* 0.10 ** 0.05 *** 0.01) r2 ar2 onecell nolines nogaps compress nomtitles nodepvars constant rtf replace

* KLD Measures of CSR Performance in 2018-2019
use data_2018_2019, clear
eststo clear
eststo r1: xi:reg cei lat lage roa col_emp labormkt ad2at b2c pps eindex iio hqdparty dparty kld_w i.cyear if gray==0&cyear>=2011, cluster(fid)
eststo r2: xi:reg stakeholder_mgmt lat lage roa col_emp labormkt ad2at b2c pps eindex iio hqdparty dparty kld_sm i.cyear if gray==0&cyear>=2011, cluster(fid)
eststo r3: xi:reg socialissue_part lat lage roa col_emp labormkt ad2at b2c pps eindex iio hqdparty dparty kld_sip i.cyear if gray==0&cyear>=2011, cluster(fid)
eststo r4: xi:reg kld_w lat lage roa col_emp labormkt ad2at b2c pps eindex iio hqdparty dparty i.cyear if gray==0&cyear>=2011, cluster(fid)
eststo r5: xi:reg kld_sm lat lage roa col_emp labormkt ad2at b2c pps eindex iio hqdparty dparty i.cyear if gray==0&cyear>=2011, cluster(fid)
eststo r6: xi:reg kld_sip lat lage roa col_emp labormkt ad2at b2c pps eindex iio hqdparty dparty i.cyear if gray==0&cyear>=2011, cluster(fid)
esttab using myfile.rtf, star(* 0.10 ** 0.05 *** 0.01) r2 ar2 onecell nolines nogaps compress nomtitles nodepvars constant rtf replace

* Determinants of Subcategories of SM: Discrimination, Benefits, and Employee Satisfaction in 2018-2019
use data_2018_2019, clear
eststo clear
eststo r1: xi:reg discrimination lat lage roa col_emp labormkt ad2at b2c pps eindex iio hqdparty dparty i.cyear if gray==0&cyear>=2011, cluster(fid)
eststo r2: xi:reg benefits lat lage roa col_emp labormkt ad2at b2c pps eindex iio hqdparty dparty i.cyear if gray==0&cyear>=2011, cluster(fid)
eststo r3: xi:reg happiness lat lage roa col_emp labormkt ad2at b2c pps eindex iio hqdparty dparty i.cyear if gray==0&cyear>=2011, cluster(fid)
esttab using myfile.rtf, star(* 0.10 ** 0.05 *** 0.01) r2 ar2 onecell nolines nogaps compress nomtitles nodepvars constant rtf replace

* Excess returns of CEI Sorted Portfolios in 2018-2019
use porc_2018_2019.dta, clear
keep if cei_g == 0
gen ym = year*12 + month
tset ym
newey ewretrf mktrf smb hml umd, lag(1)

* Excess returns of Stakeholder Management score Sorted Portfolios in 2018-2019
use pors_2018_2019.dta, clear
keep if sm_g == 0
gen ym = year * 12 + month
tset ym
newey ewretrf mktrf smb hml umd, lag(1)

* Excess returns of Social Issue Participation score Sorted Portfolios in 2018-2019
use porp_2018_2019.dta, clear
keep if sip_g == 0
gen ym = year * 12 + month
tset ym
newey ewretrf mktrf smb hml umd, lag(1)

* Industry average CEI scores in 2018-2019
use data_2018_2019, clear
gen naic1 = substr(naic2,1,1)
egen nid = group(naic1)
collapse (mean) cei stakeholder_mgmt socialissue_part kld_w, by(nid)
list

* Correlation between CEI and KLD in 2018-2019
use data_2018_2019, clear
eststo clear
estpost corr cei stakeholder_mgmt socialissue_part kld_w kld_sm kld_sip if gray==0&cyear>=2011, matrix listwise
esttab using myfile.rtf, nostar unstack not noobs compress rtf replace

* The choice of completing the surveys in 2018-2019
gen official = 1 - gray
eststo clear
xi:probit official lat lage roa col_emp labormkt ad2at b2c pps eindex iio hqdparty dparty i.cyear if cyear>=2011, vce(cluster fid)
estpost margins, dydx(lat lage roa col_emp labormkt ad2at b2c pps eindex iio hqdparty dparty)
eststo r1
esttab using myfile.rtf, star(* 0.10 ** 0.05 *** 0.01) pr2 r2 ar2 onecell nolines nogaps compress nomtitles nodepvars constant margin rtf replace

* Time Trends (This code needs the entire sample)
gen year2013 = cond(cyear>=2013,1,0)
gen p_lat = year2013 * lat
gen p_lage = year2013 * lage
gen p_roa = year2013 * roa
gen p_col = year2013 * col
gen p_labormkt = year2013 * labormkt
gen p_ad2at = year2013 * ad2at
gen p_b2c = year2013 * b2c
gen p_pps = year2013 * pps
gen p_eindex = year2013 * eindex
gen p_iio = year2013 * iio
gen p_hqdparty = year2013 * hqdparty
gen p_dparty = year2013 * dparty

eststo clear
eststo r1: xi:reg cei p_lat p_lage p_roa p_col p_labormkt p_ad2at p_b2c p_pps p_eindex p_iio p_hqdparty p_dparty lat lage roa col_emp labormkt ad2at b2c pps eindex iio hqdparty dparty i.cyear, cluster(fid)
eststo r2: xi:reg stakeholder_mgmt p_lat p_lage p_roa p_col p_labormkt p_ad2at p_b2c p_pps p_eindex p_iio p_hqdparty p_dparty lat lage roa col_emp labormkt ad2at b2c pps eindex iio hqdparty dparty i.cyear, cluster(fid)
eststo r3: xi:reg socialissue_part p_lat p_lage p_roa p_col p_labormkt p_ad2at p_b2c p_pps p_eindex p_iio p_hqdparty p_dparty lat lage roa col_emp labormkt ad2at b2c pps eindex iio hqdparty dparty i.cyear, cluster(fid)
esttab using myfile.rtf, star(* 0.10 ** 0.05 *** 0.01) r2 ar2 onecell nolines nogaps compress nomtitles nodepvars constant rtf replace
